<template>
  <el-form :model="loginForm" label-width="100px">
    <el-form-item label="用户名" prop="loginName">
      <el-input v-model="loginForm.loginName"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input v-model="loginForm.password" type="password" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit()">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  // import { mapActions } from 'vuex';
  export default {
    data() {
      return {
        loginForm: {
          loginName: '13999999999',
          password: '123456',
        },
        redirect: undefined,
      };
    },
    watch: {
      $route: {
        handler: function (route) {
          const query = route.query;
          if (query) {
            this.redirect = query.redirect;
          }
        },
        immediate: true,
      },
    },
    methods: {
      async submit() {
        try {
          const { organId } = await this.$store.dispatch('user/login', {
            deviceToken: 'Ea0kXtrE9wnWpKx3olpWDaLkfs',
            flag: 2,
            ...this.loginForm,
          });
          await this.$store.dispatch('organization/initOrgTree', organId);
          await this.$router.push('/');
        } catch (error) {}
      },
    },
  };
</script>

<style></style>
